home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / USB / Mac OS USB DDK v1.2 / Examples / USBSampleStorageDriver / SampleStorageHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  4.6 KB  |  152 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SampleStorageHeader.c
  3.  
  4.     Contains:    All exported structures and functions for the USB Manager
  5.  
  6.     Version:        1.1
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #include <MacTypes.h>
  15. #include <Devices.h>
  16. #include <DriverServices.h>
  17. #include <USB.h>
  18.  
  19. #include "SampleStorageDriver.h"
  20. #include "SampleStorageVersion.h"
  21. #include "SampleStorageDeviceID.h"
  22.  
  23. //------------------------------------------------------
  24. //
  25. // Protos
  26. //
  27. //------------------------------------------------------
  28. OSStatus StorageDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc);
  29. OSStatus StorageDriverInitDevice(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  30. OSStatus StorageDriverInitInterface( UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device);
  31. OSStatus StorageDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr desc );
  32. OSStatus    StorageDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refCon);
  33.  
  34. //------------------------------------------------------
  35. //
  36. //    This is the driver description structure that the expert looks for first.
  37. //  If it's here, the information within is used to match the driver
  38. //  to the device whose descriptor was passed to the expert.
  39. //    Information in this block is also used by the expert when an
  40. //  entry is created in the Name Registry.
  41. //
  42. //------------------------------------------------------
  43. USBDriverDescription    TheUSBDriverDescription = 
  44. {
  45.     // Signature info
  46.     kTheUSBDriverDescriptionSignature,    // 'usbd'
  47.     kInitialUSBDriverDescriptor,            // 0
  48.     
  49.     // Device Info
  50.     kDriverVendorID,                            // USB Vendor ID
  51.     kDriverProductID,                            // USB Product ID.
  52.     0,                                                // Release Number of Device
  53.     0,                                                // Protocol Info.
  54.     
  55.     // Interface Info    (* I don't think this would always be required...*)                
  56.     0,                                                // Configuration Value
  57.     0,                                                // Interface Number
  58.     kDriverClassID,                            // Interface Class        (from USBDeviceDefines.h)
  59.     kDriverSubClassID,                         // Interface SubClass    (from USBDeviceDefines.h)
  60.     0,                                                // Interface Protocol
  61.         
  62.     
  63.     // Driver Info    
  64.     "\pUSB Storage Class",                    // Driver name for Name Registry
  65.     kDriverClassID,                            // Device Class              (from USBDeviceDefines.h)
  66.     kDriverSubClassID,                        // Device Subclass         (from USBDeviceDefines.h)
  67.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease,        // version of driver = 0.0d0
  68.     
  69.     // Driver Loading Info
  70.     kUSBDoNotMatchGenericDevice    |        /* Driver's VendorID must match Device's VendorID*/
  71.     //kUSBDoNotMatchInterface        |        /* Do not load this driver as an interface driver.*/
  72.     //kUSBProtocolMustMatch            |        /* Do not load this driver if protocol field doesn't match.*/
  73.     //kUSBInterfaceMatchOnly        |        /* Only load this driver as an interface driver.*/
  74.     0                                                // To end the Driver Loading flags field
  75. };
  76.     
  77. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  78. {
  79.     kClassDriverPluginVersion,                // Version of this structure
  80.     StorageDriverValidateHW,                // Hardware Validation Procedure
  81.     StorageDriverInitDevice,                // Initialization Procedure
  82.     StorageDriverInitInterface,            // Interface Initialization Procedure
  83.     StorageDriverFinalize,                    // Finalization Procedure
  84.     StorageDriverNotifyProc,                // Driver Notification Procedure
  85. };
  86.  
  87. // Hardware Validation
  88. // Called upon load by Expert
  89. OSStatus 
  90. StorageDriverValidateHW(    USBDeviceRef            device,
  91.                                     USBDeviceDescriptor    *desc)
  92. {
  93.     device = 0;
  94.     desc = 0;
  95.     return (OSStatus)noErr;
  96. }
  97.  
  98.  
  99. // Initialization function
  100. // Called upon load by Expert
  101. OSStatus 
  102. StorageDriverInitDevice(    USBDeviceRef                device,
  103.                                     USBDeviceDescriptorPtr    pDesc,
  104.                                     UInt32                        busPowerAvailable)
  105. {
  106.     busPowerAvailable = 0;
  107.     
  108.     StorageDriverEntry(device, pDesc, NULL );
  109.     
  110.     return (OSStatus)noErr;
  111. }
  112.  
  113. // StorageDriverInitInterface function
  114. // Called to initialize driver for an individual interface - either by expert or
  115. // internally by driver
  116. OSStatus
  117. StorageDriverInitInterface(    UInt32                         interfaceNum, 
  118.                                         USBInterfaceDescriptor    *interfaceDesc, 
  119.                                         USBDeviceDescriptor        *deviceDesc, 
  120.                                         USBDeviceRef                 device)
  121. {
  122.     interfaceNum = 0;
  123.  
  124.     StorageDriverEntry(device, deviceDesc, interfaceDesc );
  125.     
  126.     return (OSStatus)noErr;
  127. }
  128.  
  129. // Termination function
  130. // Called by Expert when driver is being shut down
  131. OSStatus
  132. StorageDriverFinalize(    USBDeviceRef                device,
  133.                                 USBDeviceDescriptorPtr    desc )
  134. {
  135. #pragma unused(device)
  136. #pragma unused(desc)
  137.  
  138.     StorageClassDriverFinalize();
  139.  
  140.     return (OSStatus)noErr;
  141. }
  142.  
  143. OSStatus    
  144. StorageDriverNotifyProc(UInt32    notification,
  145.                                 void*        pointer,
  146.                                 UInt32    refCon)
  147. {
  148. #pragma unused(refCon)
  149.  
  150.     return(StorageClassDriverNotifyProc(notification, pointer));
  151. }
  152.